package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingElderDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import static com.zzyl.base.ResponseResult.success;

@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页条件查询护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> selectByPage(@ApiParam(value = "护理项目名称")String name,
                                                                       @ApiParam(value = "护理项目状态") Integer status,
                                                                       @ApiParam(value = "分页页码")@RequestParam(value = "pageNum", defaultValue = "1")Integer pageNum,
                                                                       @ApiParam(value = "每页显示记录数")@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize){
        PageResponse pageResponse = nursingProjectService.selectByPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult insert(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.insert(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> selectById(
            @ApiParam(value = "护理项目id") @PathVariable("id") Long id){
        NursingProjectVo vo = nursingProjectService.selectById(id);
        return success(vo);
    }

    @PutMapping
    @ApiOperation("根据id修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理项目")
    public ResponseResult delete(@PathVariable("id") Long id){
        nursingProjectService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理项目状态")
    public ResponseResult updateStatus(@PathVariable Long id,@PathVariable Integer status){
        nursingProjectService.updeteStatue(id,status);
        return success();
    }
}
